//
//  MainTabBarController.swift
//  weibo
//
//  Created by Mike on 15/5/10.
//  Copyright (c) 2015年 Mike. All rights reserved.
//

import UIKit

class MainTabBarController: UITabBarController {

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.addChildViewControllers()
        
//        sortChildViewControllers()
    }
    
//    func sortChildViewControllers() {
//        let first = self.view.subviews[0] as! UITabBarItem
//        
//    }
    
    func addChildViewControllers() {
        self.tabBar.tintColor = UIColor.orangeColor() // 包含了设置文字的颜色
        
        self.addChildViewController("Home", title: "首页", imageName: "tabbar_home")
        self.addChildViewController("Message", title: "消息", imageName: "tabbar_message_center")
        self.addChildViewController("Discover", title: "发现", imageName: "tabbar_discover")
        self.addChildViewController("Profile", title: "我", imageName: "tabbar_profile")
        
        
    }
    func addChildViewController(sbName: String, title: String, imageName: String) {
        let sb = UIStoryboard(name: sbName, bundle: nil)
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        
        nav.tabBarItem.title = title
        nav.topViewController.title = title
        nav.tabBarItem.image = UIImage(named: imageName)
        nav.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted") // 需要修改渲染模式
        
        self.addChildViewController(nav)
    }

}
